package com.huaqing.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.huaqing.common.annotation.Log;
import com.huaqing.common.core.controller.BaseController;
import com.huaqing.common.core.domain.AjaxResult;
import com.huaqing.common.enums.BusinessType;
import com.huaqing.manage.domain.MaterialRecord;
import com.huaqing.manage.service.IMaterialRecordService;
import com.huaqing.common.utils.poi.ExcelUtil;
import com.huaqing.common.core.page.TableDataInfo;

/**
 * 仓库管理Controller
 * 
 * @author cdutTang
 * @date 2025-02-28
 */
@RestController
@RequestMapping("/manage/record")
public class MaterialRecordController extends BaseController
{
    @Autowired
    private IMaterialRecordService materialRecordService;

    /**
     * 查询仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialRecord materialRecord)
    {
        startPage();
        List<MaterialRecord> list = materialRecordService.selectMaterialRecordList(materialRecord);
        return getDataTable(list);
    }

    /**
     * 导出仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:record:export')")
    @Log(title = "仓库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialRecord materialRecord)
    {
        List<MaterialRecord> list = materialRecordService.selectMaterialRecordList(materialRecord);
        ExcelUtil<MaterialRecord> util = new ExcelUtil<MaterialRecord>(MaterialRecord.class);
        util.exportExcel(response, list, "仓库管理数据");
    }

    /**
     * 获取仓库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(materialRecordService.selectMaterialRecordByRecordId(recordId));
    }

    /**
     * 新增仓库管理
     */
    @PreAuthorize("@ss.hasPermi('manage:record:add')")
    @Log(title = "仓库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialRecord materialRecord)
    {
        return toAjax(materialRecordService.insertMaterialRecord(materialRecord));
    }

    /**
     * 修改仓库管理
     */
    @PreAuthorize("@ss.hasPermi('manage:record:edit')")
    @Log(title = "仓库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialRecord materialRecord)
    {
        return toAjax(materialRecordService.updateMaterialRecord(materialRecord));
    }

    /**
     * 删除仓库管理
     */
    @PreAuthorize("@ss.hasPermi('manage:record:remove')")
    @Log(title = "仓库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(materialRecordService.deleteMaterialRecordByRecordIds(recordIds));
    }
}
